<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/2/20
 * Time: 16:08
 */

namespace app\server;


class request
{
    public function getMethod ($url, $where) {
        $param = http_build_query($where);
        $url = $url ."&". $param;

        //初始化curl
        $ch = curl_init();
        //设置访问url
        curl_setopt($ch, CURLOPT_URL, $url);
        //设置头信息
        curl_setopt($ch, CURLOPT_HEADER, 0);
        //捕获内容，但不输出
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        //设置请求超时时间
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);

        $data = curl_exec($ch);
        //数据json解析
        $data = json_decode($data, true);
        //关闭curl
        curl_close($ch);
        //返回数据
        return $data;
    }

    public function getRequestMethod ($url, $where) {
        $param = http_build_query($where);
        $url = $url . $param;

        //初始化curl
        $ch = curl_init();
        //设置访问url
        curl_setopt($ch, CURLOPT_URL, $url);
        //设置头信息
        curl_setopt($ch, CURLOPT_HEADER, 0);
        //捕获内容，但不输出
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        //设置请求超时时间
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);

        $data = curl_exec($ch);
        //数据json解析
        $data = json_decode($data, true);
        //关闭curl
        curl_close($ch);
        //返回数据
        return $data;
    }
}